//
//  CAnAlgExerData.m
//  sr01sdkProject
//
//  Created by  on 2024/9/3.
//

#import "CAnAlgExerData.h"

@implementation CAnAlgExerData
-(NSNumber *)dataTimeStamp
{
    return @(self.timeStamp);
}
- (instancetype)initWithData:(NSData *)data
{
    if (self = [super init]) {
        if (data.length < 20) {
            return self;
        }
        
        uint8_t *dataBytes = (uint8_t *)[data bytes];
        _cmdByte = dataBytes[1];
        // 四字节时间戳
        uint32_t timeStamp = *((uint32_t *)(dataBytes + 2));
        _timeStamp = timeStamp;
        
        _steps = *((uint16_t *)(dataBytes + 6)) & 0XFFFF;
        
        _distance = dataBytes[8] / 10.0f;
        
        _speed = dataBytes[9];
        _cadence = dataBytes[10]; // 步频
        _wholeEnergyCnsmptn =  *((uint16_t *)(dataBytes + 11)) & 0XFFFF;
        _activityEnergyCnsmptn = *((uint16_t *)(dataBytes + 13)) & 0XFFFF;
        _met = (*((uint16_t *)(dataBytes + 15)) & 0XFFFF) /10.0f;
        _exerType = dataBytes[17];
        _heartRate = dataBytes[18];
        
    }
    return self;
}

@end
